import {Component} from "react";
import ChildCmt from "../component/ChildCmt";
import {Button} from "antd";


class LifeCycleIndex extends Component{
    constructor() {
        super();
        console.log('constructor')
        this.state = {
            count: 0
        }
    }

    add =() => {
        let {count} = this.state;
        this.setState({
            count: ++count
        })
    }


    // 是否更新
    shouldComponentUpdate(nextProps, nextState, nextContext) {
        return true
    }

    //将要挂载
    componentWillMount() {
        console.log('componentWillMount')
    }

    // 挂载
    componentDidMount() {
        console.log('componentDidMount')
    }

    // 卸载
    componentWillUnmount() {
        console.log('componentWillUnmount')
    }


    render() {
        const{count} = this.state;
        console.log('render')
        return(
            <div>
                <h2>V6版本生命周期</h2>
                <h3>这是生命长度：{count}</h3>
                <Button type='primary' onClick={this.add}>新增</Button>
                <ChildCmt count={count}/>
            </div>
        )
    }
}

export default LifeCycleIndex;